import java.util.ArrayList;

public class Vertex {
	private ArrayList<Edge> inComingEdges;
	private ArrayList<Edge> outGoingEdges;
	private String name;
	private int earliestTime;
	private int lastTime;

	public Vertex(String name) {
		this.name = name;
		inComingEdges = new ArrayList<Edge>();
		outGoingEdges = new ArrayList<Edge>();
	}

	public void addIncomingEdge(Edge e) {
		inComingEdges.add(e);
	}

	public void addOutgoingEdge(Edge e) {
		outGoingEdges.add(e);
	}

	public ArrayList<Edge> getInComingEdges() {
		return inComingEdges;
	}

	public void setInComingEdges(ArrayList<Edge> inComingEdges) {
		this.inComingEdges = inComingEdges;
	}

	public void removeEdge(Edge e) {
		inComingEdges.remove(e);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void removeEdges() {
		inComingEdges = new ArrayList<Edge>();
	}

	public Edge getEdge(Vertex source) {
		Edge edge = null;
		for (Edge e : inComingEdges) {
			if (e.getStartVertex().equals(source)) {
				edge = e;
				break;
			}
		}
		return edge;
	}

	public int getEarliestTime() {
		return earliestTime;
	}

	public void setEarliestTime(int earliestTime) {
		this.earliestTime = earliestTime;
	}

	public int getLastTime() {
		return lastTime;
	}

	public void setLastTime(int lastTime) {
		this.lastTime = lastTime;
	}

	public Vertex getFirstTimePredecessors() {
		Vertex v = null;
		int value = 0;
		for (Edge e : inComingEdges) {
			if (v != null) {
				if (e.getStartVertex().earliestTime + e.getEdgeValue() > v
						.getEarliestTime() + value) {
					v = e.getStartVertex();
				}
			} else {
				v = e.getStartVertex();
				value = e.getEdgeValue();
			}
		}
		return v;
	}

	public String toString() {

		return "(" + name + "[" + earliestTime + ", " + lastTime + "] )";
	}

	public ArrayList<Edge> getOutGoingEdges() {
		return outGoingEdges;
	}

	public void setOutGoingEdges(ArrayList<Edge> outGoingEdges) {
		this.outGoingEdges = outGoingEdges;
	}
}
